package com.mrduan.otgfilemanager.ui_sdcard.main.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.mrduan.otgfilemanager.Config;
import com.mrduan.otgfilemanager.R;
import com.mrduan.otgfilemanager.ui_sdcard.video.ListVideoActivity;
import com.shike.baselibrary.fragment.BaseFragment;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by snoopy on 2018/5/2.
 */

public class ThreeScreenFragment extends BaseFragment implements View.OnClickListener{

    private TextView text1,text2,text3,text4,text5,text6,text7,text8;
    private List<String> mFilePath = new ArrayList<>();

    @Override
    public void initGetDataFromParent(Bundle savedInstanceState) {

    }

    @Override
    public int initSetContentView() {
        return R.layout.three_screen_fragment;
    }

    @Override
    public void initBindWidget(Bundle savedInstanceState) {

        text1 = getView(R.id.three_text_1);
        text2 = getView(R.id.three_text_2);
        text3 = getView(R.id.three_text_3);
        text4 = getView(R.id.three_text_4);
        text5 = getView(R.id.three_text_5);
        text6 = getView(R.id.three_text_6);
        text7 = getView(R.id.three_text_7);
        text8 = getView(R.id.three_text_8);

    }

    @Override
    public void initSetListener() {
        getView(R.id.three_btn_1).setOnClickListener(this);
        getView(R.id.three_btn_2).setOnClickListener(this);
        getView(R.id.three_btn_3).setOnClickListener(this);
        getView(R.id.three_btn_4).setOnClickListener(this);
        getView(R.id.three_btn_5).setOnClickListener(this);
        getView(R.id.three_btn_6).setOnClickListener(this);
        getView(R.id.three_btn_7).setOnClickListener(this);
        getView(R.id.three_btn_8).setOnClickListener(this);
    }

    @Override
    public void initSetData() {
        List<String> fileName = new ArrayList<>();

        for (String arg : Config.threeScreenFiles) {
            File file = new File(Config.BASE_FILE_PATH + "/" + arg);
            File[] files = file.listFiles();
            for (File f : files) {
                if (f.isDirectory()) {
                    fileName.add(f.getName());
                    mFilePath.add(f.getPath());
                    break;
                }
            }
        }

        if (fileName.size() >= 8) {
            text1.setText(fileName.get(0));
            text2.setText(fileName.get(1));
            text3.setText(fileName.get(2));
            text4.setText(fileName.get(3));
            text5.setText(fileName.get(4));
            text6.setText(fileName.get(5));
            text7.setText(fileName.get(6));
            text8.setText(fileName.get(7));
        }

    }

    @Override
    public void onClick(View view) {
        String path = "";
        String title = "";
        switch (view.getId()) {
            case R.id.three_btn_1:
                path = mFilePath.get(0);
                title = text1.getText().toString();
                break;
            case R.id.three_btn_2:
                path = mFilePath.get(1);
                title = text2.getText().toString();
                break;
            case R.id.three_btn_3:
                path = mFilePath.get(2);
                title = text3.getText().toString();
                break;
            case R.id.three_btn_4:
                path = mFilePath.get(3);
                title = text4.getText().toString();
                break;
            case R.id.three_btn_5:
                path = mFilePath.get(4);
                title = text5.getText().toString();
                break;
            case R.id.three_btn_6:
                path = mFilePath.get(5);
                title = text6.getText().toString();
                break;
            case R.id.three_btn_7:
                path = mFilePath.get(6);
                title = text7.getText().toString();
                break;
            case R.id.three_btn_8:
                path = mFilePath.get(7);
                title = text8.getText().toString();
                break;
        }

        Intent intent = new Intent(getContext(), ListVideoActivity.class);
        intent.putExtra("title",title);
        intent.putExtra("path",path);
        startActivity(intent);

    }
}
